package lily.phs.object;

import lily.phs.database.Constants;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


public class SickbedHistory implements Constants{
	
	private Context mContext;
	
	private int sihi_profileid=-1;
	private int sihi_testid=-1;
	private int sihi_id=-1;
	private String sihi_setup_date="";
	private String sihi_cancel_date="";
	private String sihi_reason="";
	private String sihi_hospital="";
	private String sihi_number="";
	
	public SickbedHistory(Context context){
		this.mContext=context;
	}

	

	public int getSihi_profileid() {
		return sihi_profileid;
	}



	public void setSihi_profileid(int sihi_profileid) {
		this.sihi_profileid = sihi_profileid;
	}



	public int getSihi_testid() {
		return sihi_testid;
	}



	public void setSihi_testid(int sihi_testid) {
		this.sihi_testid = sihi_testid;
	}



	public int getSihi_id() {
		return sihi_id;
	}



	public void setSihi_id(int sihi_id) {
		this.sihi_id = sihi_id;
	}



	public String getSihi_setup_date() {
		return sihi_setup_date;
	}

	public void setSihi_setup_date(String sihi_setup_date) {
		this.sihi_setup_date = sihi_setup_date;
	}

	public String getSihi_cancel_date() {
		return sihi_cancel_date;
	}

	public void setSihi_cancel_date(String sihi_cancel_date) {
		this.sihi_cancel_date = sihi_cancel_date;
	}

	public String getSihi_reason() {
		return sihi_reason;
	}

	public void setSihi_reason(String sihi_reason) {
		this.sihi_reason = sihi_reason;
	}

	public String getSihi_hospital() {
		return sihi_hospital;
	}

	public void setSihi_hospital(String sihi_hospital) {
		this.sihi_hospital = sihi_hospital;
	}

	public String getSihi_number() {
		return sihi_number;
	}

	public void setSihi_number(String sihi_number) {
		this.sihi_number = sihi_number;
	}
	
	public void insertSickbedHistory(){
//		int result = -1;
		ContentValues value = new ContentValues();
		value.put(SIHI_COLUMN1, this.getSihi_profileid());
		value.put(SIHI_COLUMN7, this.getSihi_testid());
		value.put(SIHI_COLUMN8, this.getSihi_id());
		value.put(SIHI_COLUMN2, this.getSihi_setup_date());
		value.put(SIHI_COLUMN3, this.getSihi_cancel_date());
		value.put(SIHI_COLUMN4, this.getSihi_reason());
		value.put(SIHI_COLUMN5, this.getSihi_hospital());
		value.put(SIHI_COLUMN6, this.getSihi_number());
		
		mContext.getContentResolver().insert(CONTENT_URI_TB7, value);
//		return result;
		
	}
	
	/**
	 * 检出病床史信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 病床史编号
	 */
	public void selectSickbedHistory(int profileId,int testId,int _Id){

		String where = SIHI_COLUMN8 + "=" + _Id + " and "+SIHI_COLUMN1 + "=" + profileId + " and "+SIHI_COLUMN7 + "=" + testId + "";
		Cursor cursor = mContext.getContentResolver().query(CONTENT_URI_TB7, null, where, null, null);
		if(cursor.moveToNext()){
		this.sihi_profileid = cursor.getInt(cursor.getColumnIndex(SIHI_COLUMN1));
		this.sihi_testid = cursor.getInt(cursor.getColumnIndex(SIHI_COLUMN7));
		this.sihi_id = cursor.getInt(cursor.getColumnIndex(SIHI_COLUMN8));
		this.sihi_setup_date = cursor.getString(cursor.getColumnIndex(SIHI_COLUMN2));
		this.sihi_cancel_date = cursor.getString(cursor.getColumnIndex(SIHI_COLUMN3));
		this.sihi_reason = cursor.getString(cursor.getColumnIndex(SIHI_COLUMN4));
		this.sihi_hospital = cursor.getString(cursor.getColumnIndex(SIHI_COLUMN5));
		this.sihi_number = cursor.getString(cursor.getColumnIndex(SIHI_COLUMN6));
		}
		cursor.close();
	}
	
	/**
	 * 更新病床史信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 病床史编号
	 */
	public void updateSickbedHistory(int profileId,int testId,int _Id){
		ContentValues value = new ContentValues();

		value.put(SIHI_COLUMN1, this.getSihi_profileid());
		value.put(SIHI_COLUMN7, this.getSihi_testid());
		value.put(SIHI_COLUMN8, this.getSihi_id());
		value.put(SIHI_COLUMN2, this.getSihi_setup_date());
		value.put(SIHI_COLUMN3, this.getSihi_cancel_date());
		value.put(SIHI_COLUMN4, this.getSihi_reason());
		value.put(SIHI_COLUMN5, this.getSihi_hospital());
		value.put(SIHI_COLUMN6, this.getSihi_number());
		
		String where = SIHI_COLUMN8 + "=" + _Id + " and "+SIHI_COLUMN1 + "=" + profileId + " and "+SIHI_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().update(CONTENT_URI_TB7, value, where, null);
		
	}
	
	/**
	 * 删除患者的某次病床史信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 病床史编号
	 */
	public void delectSickbedHistory(int profileId,int testId,int _Id){
		String where = SIHI_COLUMN8 + "=" + _Id + " and "+SIHI_COLUMN1 + "=" + profileId + " and "+SIHI_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB7, where, null);
		
	}
	
	/**
	 * 删除患者的全部病床史纪录
	 * @param profileId 档案编号
	 */
	public void delectSickbedHistory(int profileId){
		String where = SIHI_COLUMN1 + "=" + profileId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB7, where, null);
		
	}
	

}
